﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using KPWeb.Class;
using KPWeb.Data;
using KPWeb.Function;
using Microsoft.Reporting.WebForms;

namespace KPWeb.Reports
{
    public class RaportyPDF
    {
        public static void RaportWniosekUrlopowyBarCodePDF(int id, byte typ)//typ:0-roboczy, 1 oryginal
        {
             string raportName="WniosekUrlopowy.rdlc";
            KPWeb.Function.Barcode.TextToBarCode = id.ToString();// "019876549";
            if (KPWeb.Function.Barcode.TextToBarCode.Length < Stale.countDigitsInBarCode)
                KPWeb.Function.Barcode.TextToBarCode = "0" + KPWeb.Function.Barcode.TextToBarCode;    
            KPWeb.Function.Barcode.IsVerticalTextToBarCode = true;
        //    KPWeb.Function.Barcode.TextToBarCode =  "123456789";
            List<ReportDataSource> rds = new List<ReportDataSource>();
            rds.Add(new ReportDataSource("DataSet1", KPWeb.Function.Barcode.GetBarcode()));
            KPWeb.Function.Barcode.IsVerticalTextToBarCode = false;
            rds.Add(new ReportDataSource("DataSet2", KPWeb.Function.Barcode.GetBarcode()));
            int iTemp = id % 10000000;
            string sTemp = "";

            vKP_DrukWniosekUrlopowy[] t = UrlopyK.GetDrukWniosekUrlopowy(iTemp);
            rds.Add(new ReportDataSource("DataSet3", UrlopyK.GetDrukWniosekUrlopowy(iTemp)));

            List<Microsoft.Reporting.WebForms.ReportParameter> l = new List<ReportParameter>();

            l.Add(new Microsoft.Reporting.WebForms.ReportParameter("P1",
                typ==0?"0":KPWeb.Function.Barcode.TextToBarCode));
            l.Add(new Microsoft.Reporting.WebForms.ReportParameter("P2",
                FunctionGlobal.UppercaseFirstWords(t.Single().NazwiskoImie)));
            if (t.Single().Zastepstwo != null) sTemp = FunctionGlobal.UppercaseFirstWords(t.Single().Zastepstwo);

            l.Add(new Microsoft.Reporting.WebForms.ReportParameter("P3", sTemp));
            //for (int i = 0; i < parametry.Length; i++)
            //{
            //    l.Add(new Microsoft.Reporting.WebForms.ReportParameter(parametry[0][i],parametry[1][i]));
            //}

            //Microsoft.Reporting.WebForms.LocalReport report = KPWeb.Reports.LocalReport.GenerujRaport("WniosekUrlop.rdlc", rds, l);
            Microsoft.Reporting.WebForms.LocalReport report = KPWeb.Reports.LocalReport.GenerujRaport(raportName, rds, l);
            //    KPWeb.Reports.LocalReport.Export(report, "Excel", "RankingNauczycieli.xls");
            KPWeb.Reports.LocalReport.Export(report, "PDF", raportName.Substring(0, raportName.Length - 4) + "pdf");
        }
        //public static void RaportDyzuryBarCodePDF(int id, byte typ)//typ:0-roboczy, 1 oryginal
        //{
        //    string raportName = "Dyzury.rdlc";
        //    KPWeb.Function.Barcode.TextToBarCode = id.ToString();// "019876549";
        //    if (KPWeb.Function.Barcode.TextToBarCode.Length < Stale.countDigitsInBarCode)
        //        KPWeb.Function.Barcode.TextToBarCode = "0" + KPWeb.Function.Barcode.TextToBarCode;
        //    KPWeb.Function.Barcode.IsVerticalTextToBarCode = true;
        //    //    KPWeb.Function.Barcode.TextToBarCode =  "123456789";
        //    List<ReportDataSource> rds = new List<ReportDataSource>();
        //    rds.Add(new ReportDataSource("DataSet1", KPWeb.Function.Barcode.GetBarcode()));
        //    KPWeb.Function.Barcode.IsVerticalTextToBarCode = false;
        //    rds.Add(new ReportDataSource("DataSet2", KPWeb.Function.Barcode.GetBarcode()));
        //    int iTemp = id % 10000000;
        //    string sTemp = "";

        //    vKP_DrukWniosekUrlopowy[] t = UrlopyK.GetDrukWniosekUrlopowy(iTemp);
        //    rds.Add(new ReportDataSource("DataSet3", UrlopyK.GetDrukWniosekUrlopowy(iTemp)));

        //    List<Microsoft.Reporting.WebForms.ReportParameter> l = new List<ReportParameter>();

        //    l.Add(new Microsoft.Reporting.WebForms.ReportParameter("P1",
        //        typ == 0 ? "0" : KPWeb.Function.Barcode.TextToBarCode));
        //    l.Add(new Microsoft.Reporting.WebForms.ReportParameter("P2",
        //        FunctionGlobal.UppercaseFirstWords(t.Single().NazwiskoImie)));
        //    if (t.Single().Zastepstwo != null) sTemp = FunctionGlobal.UppercaseFirstWords(t.Single().Zastepstwo);

        //    l.Add(new Microsoft.Reporting.WebForms.ReportParameter("P3", sTemp));
        //    //for (int i = 0; i < parametry.Length; i++)
        //    //{
        //    //    l.Add(new Microsoft.Reporting.WebForms.ReportParameter(parametry[0][i],parametry[1][i]));
        //    //}

        //    //Microsoft.Reporting.WebForms.LocalReport report = KPWeb.Reports.LocalReport.GenerujRaport("WniosekUrlop.rdlc", rds, l);
        //    Microsoft.Reporting.WebForms.LocalReport report = KPWeb.Reports.LocalReport.GenerujRaport(raportName, rds, l);
        //    //    KPWeb.Reports.LocalReport.Export(report, "Excel", "RankingNauczycieli.xls");
        //    KPWeb.Reports.LocalReport.Export(report, "PDF", raportName.Substring(0, raportName.Length - 4) + "pdf");
        //}

        public static void RaportPlanUrlopowyBarCodePDF(int id, int jednostkaID, int grupaID, int year)
        {
            string raportName = "PlanyUrlopowe.rdlc";
            KPWeb.Function.Barcode.TextToBarCode = id.ToString();
            if (KPWeb.Function.Barcode.TextToBarCode.Length < Stale.countDigitsInBarCode)
                KPWeb.Function.Barcode.TextToBarCode = "0" + KPWeb.Function.Barcode.TextToBarCode; 
            KPWeb.Function.Barcode.IsVerticalTextToBarCode = true;
            List<ReportDataSource> rds = new List<ReportDataSource>();
            rds.Add(new ReportDataSource("DataSet1", KPWeb.Function.Barcode.GetBarcode()));
            KPWeb.Function.Barcode.IsVerticalTextToBarCode = false;
            rds.Add(new ReportDataSource("DataSet2", KPWeb.Function.Barcode.GetBarcode()));
            int iTemp = id % 10000000;

            rds.Add(new ReportDataSource("DataSet3", Osoby.GetListaOsobPlanyUrlopow(jednostkaID,grupaID,year)));



            List<Microsoft.Reporting.WebForms.ReportParameter> l = new List<ReportParameter>();
            l.Add(new Microsoft.Reporting.WebForms.ReportParameter("P1", KPWeb.Function.Barcode.TextToBarCode));
                
            Microsoft.Reporting.WebForms.LocalReport report = KPWeb.Reports.LocalReport.GenerujRaport(raportName, rds, l);
            KPWeb.Reports.LocalReport.Export(report, "PDF", raportName.Substring(0, raportName.Length - 4) + "pdf");
        }
        public static void RaportHarmonogramBarCodePDF(int id,int jednostkaID, int osobaID, int month, int year)
        {
            string raportName = "HarmonogramMiesiac.rdlc";
            KPWeb.Function.Barcode.TextToBarCode = id.ToString();
            if (KPWeb.Function.Barcode.TextToBarCode.Length < Stale.countDigitsInBarCode)
                KPWeb.Function.Barcode.TextToBarCode = "0" + KPWeb.Function.Barcode.TextToBarCode;
            KPWeb.Function.Barcode.IsVerticalTextToBarCode = true;
            List<ReportDataSource> rds = new List<ReportDataSource>();
            rds.Add(new ReportDataSource("DataSet1", KPWeb.Function.Barcode.GetBarcode()));
            KPWeb.Function.Barcode.IsVerticalTextToBarCode = false;
            rds.Add(new ReportDataSource("DataSet2", KPWeb.Function.Barcode.GetBarcode()));
            int iTemp = id % 10000000;

            rds.Add(new ReportDataSource("DataSet3", Osoby.GetListaOsobPlanyUrlopow(194, 2, 2013)));



            List<Microsoft.Reporting.WebForms.ReportParameter> l = new List<ReportParameter>();
            l.Add(new Microsoft.Reporting.WebForms.ReportParameter("P1", KPWeb.Function.Barcode.TextToBarCode));

            Microsoft.Reporting.WebForms.LocalReport report = KPWeb.Reports.LocalReport.GenerujRaport(raportName, rds, l);
            KPWeb.Reports.LocalReport.Export(report, "PDF", raportName.Substring(0, raportName.Length - 4) + "pdf");
        }
    }
}